<script setup lang="ts">
import { Compass, Filter, MoreFilled } from "@element-plus/icons-vue"
import { markRaw, ref } from "vue"

const emits = defineEmits(["click"])
const activeIndex = ref(-1)
const list = ref([
  {
    icon: markRaw(MoreFilled),
    title: "选择",
    type: "select"
  },
  {
    icon: markRaw(Filter),
    title: "高亮",
    type: "highlight"
  },
  {
    icon: markRaw(Compass),
    title: "变暗",
    type: "clearHighlight"
  }
])
function handleClick(index: number) {
  activeIndex.value = index
  const type = list.value[index].type
  emits("click", type)
}
</script>

<template>
  <div class="toolContainer">
    <div class="tools">
      <div
        class="tool"
        :title="item.title"
        @click="handleClick(index)"
        :class="{ selected: activeIndex === index }"
        v-for="(item, index) in list" :key="index"
      >
        <el-icon>
          <component :is="item.icon" />
        </el-icon>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.toolContainer {
  align-items: center;
  display: flex;
  height: 100%;
  justify-content: center;
  position: absolute;
  right: 0.75rem;
  top: 0;
  z-index: 50;
  .tools {
    --tw-bg-opacity: 1;
    --tw-text-opacity: 1;
    --tw-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity));
    border-radius: 0.75rem;
    box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
    color: rgba(31, 41, 55, var(--tw-text-opacity));
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    padding-bottom: 0.75rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    padding-top: 0.75rem;
    transition-duration: 0.15s;
    transition-duration: 0.2s;
    transition-property:
      background-color,
      border-color,
      color,
      fill,
      stroke,
      opacity,
      box-shadow,
      transform,
      filter,
      -webkit-backdrop-filter;
    transition-property:
      background-color, border-color, color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;
    transition-property:
      background-color,
      border-color,
      color,
      fill,
      stroke,
      opacity,
      box-shadow,
      transform,
      filter,
      backdrop-filter,
      -webkit-backdrop-filter;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    .tool {
      --tw-text-opacity: 1;
      align-items: center;
      background-color: transparent;
      border-color: transparent;
      border-radius: 0.5rem;
      border-width: 1px;
      color: rgba(75, 85, 99, var(--tw-text-opacity));
      cursor: pointer;
      display: flex;
      font-size: 1.125rem;
      height: 2rem;
      justify-content: center;
      line-height: 1.75rem;
      transition-duration: 0.15s;
      transition-duration: 0.2s;
      transition-property:
        background-color,
        border-color,
        color,
        fill,
        stroke,
        opacity,
        box-shadow,
        transform,
        filter,
        -webkit-backdrop-filter;
      transition-property:
        background-color, border-color, color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;
      transition-property:
        background-color,
        border-color,
        color,
        fill,
        stroke,
        opacity,
        box-shadow,
        transform,
        filter,
        backdrop-filter,
        -webkit-backdrop-filter;
      transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
      width: 2rem;
      &.selected {
        --tw-text-opacity: 1;
        --tw-shadow: 0px 0px 8px 0px rgba(139, 92, 246, 0.25);
        background-color: #6d28d9;
        box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
        color: rgba(255, 255, 255, var(--tw-text-opacity));
      }
    }
  }
}
</style>
